/**
 * 
 */
package com.avocado.base.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.avocado.base.enums.ResourcesType;
import lombok.Data;


/**
 * 系统资源
 *
 * @author wenfeng.xu
 *2011-4-10下午01:24:21
 */

@Entity
@Table(name="AVO_RESOURCES")
@JsonIgnoreProperties(value={"resourcesRoles"})
@Data
public class Resources implements Serializable {

	private static final long serialVersionUID = 1891455076505342282L;
	@Id@Column(name="ID",nullable=false)
	@GeneratedValue(strategy = GenerationType.TABLE,generator="id_gen")
    @TableGenerator(name = "id_gen",pkColumnValue="RESOURCES_ID",table="AVO_ID_GENERATOR", pkColumnName="GEN_NAME",valueColumnName="GEN_VALUE",allocationSize=1)
	private Long id;
	
	@Column(name="name",nullable=false,length=100)
	private String name;//中文名
	
	@Column(name="code",length=100,unique=true)
	private String code;//代码

	//如果不标注EnumType.STRING则字段将记录0，1，2 等索引顺序
	@Enumerated@Column(length=5,name="TYPE",nullable=false)
	private ResourcesType type=ResourcesType.MENU;
	//链接
	@Column(name="URL")
	private String url="";
	//备注
	@Column(name="memo")
	private String memo="";
	//父ID
	@Column(name="PARENT_ID",nullable=false)
	private long parentId=0;
	//图标样式
	@Column(name="ICON_CLS")
	private String iconCls="";
	//排序
	@Column(name="SORT_ORDER",nullable=false)
	private Integer sortOrder=0;
	//创建时间
	@Column(name="CREATE_TIME")
	private Date createTime=new Date();
	//更新时间
	@Column(name="UPDATE_TIME")
	private Date updateTime=new Date();
	
	
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="resources")
	private Set<ResourcesRole> resourcesRoles =new HashSet<ResourcesRole>();


	
	public Long getId() {
		return id;
	}


	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Resources resources = (Resources) o;
		return Objects.equals(id, resources.id);
	}

	@Override
	public int hashCode() {
		return Objects.hash(id);
	}
}
